.com
Hosted by:
Unit testing expertise at your fingertips!
Home | Discuss | Lists

Minimize Data

The book has now been published and the content of this chapter has likely changed substanstially.

Also known as: Reduce Data

The test fixture is too large making the test hard to understand.

We remove things from the fixture until we have a Minimal Fixture.

From [RTC].

Minimize the data that is setup in fixtures to the bare essentials. This will have two advantages: (1) it make(s) them better suitable as documentation, and (2) your tests will be less sensitive to changes.

Implementation Notes

Reducing the data in our test fixture to the bare minimum results in a Minimal Fixture (page X) that helps the tests achieve Tests as Documentation (see Goals of Test Automation on page X). How we do this depends on how our Test Methods (page X) are organized into Testcase Classes (page X):

When our Test Methods are organized in a Testcase Class per Fixture (page X) and we believe we have a General Fixture (see Obscure Test on page X), we can remove the fixture set up logic for any parts of the fixture that we suspect is not used by the tests. It is best to do this incrementally so that if a test fails, we can undo our most recent change and try again.

When our Test Methods are organized in a Testcase Class per Feature (page X) or a Testcase Class per Class (page X), Minimize Data may also involve copying fixture set up logic from the setUp method of a Testcase Class or Setup Decorator (page X) into each test that needs the fixture. Assuming the collection of objects in the Shared Fixture (page X) is overkill for any one test, we can use a series of Extract Method[Fowler] refactorings to create a set of Creation Methods (page X) that we can call from the tests. We would then remove the calls to the Creation Methods from the setUp method and put them into only those Test Methods that require that part of the original fixture. The final step would be to convert any instance variables into local variables .



Page generated at Wed Feb 09 16:39:52 +1100 2011

Copyright © 2003-2008 Gerard Meszaros all rights reserved

All Categories
Introductory Narratives
Web Site Instructions
Code Refactorings
Database Patterns
DfT Patterns
External Patterns
Fixture Setup Patterns
Fixture Teardown Patterns
Front Matter
Glossary
Misc
References
Result Verification Patterns
Sidebars
Terminology
Test Double Patterns
Test Organization
Test Refactorings
Test Smells
Test Strategy
Tools
Value Patterns
XUnit Basics
xUnit Members
All "Test Refactorings"
Extract Testable Component
Inline Resource
Make Resource Unique
Minimize Data
--Reduce Data
Replace Dependency with Test Double
Setup External Resource